import 'package:flutter/material.dart';
import 'package:flutter01/global.dart';
import 'package:flutter01/stateManagement/bloc/demo_view.dart';
import 'package:flutter01/stateManagement/provider/provider_page.dart';
import 'package:flutter01/stateManagement/riverpod/riverpod_page.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hexcolor/hexcolor.dart';

class StateManagemenPage extends StatefulWidget {
  const StateManagemenPage({Key? key}) : super(key: key);

  @override
  State<StateManagemenPage> createState() => _StateManagemenPageState();
}

class _StateManagemenPageState extends State<StateManagemenPage> {
  int _currentIndex = 0;
  List<Widget> list = [
    BlocPage(),
    ProviderPage(),
    RiverpodPage(),
  ];
  @override
  Widget build(BuildContext context) {
    return Container(
      color: HexColor("#EEEEEE"),
      padding: EdgeInsets.all(7),
      child: Row(
        children: [
          Container(
              width: Global.WHS ? 50.w : 60.w,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Column(
                children: [
                  Container(
                    alignment: Alignment.center,
                    height: 30.h,
                    decoration: BoxDecoration(
                      color: Colors.deepOrangeAccent,
                      borderRadius: BorderRadius.vertical(top: Radius.circular(10)),
                    ),
                    child: Text("状态管理", style: TextStyle(fontSize: Global.WHS ? 15.sp : 12.sp)),
                  ),
                  Expanded(
                    child: ListView(
                      children: [
                        ListTile(
                          onTap: () => setState(() => _currentIndex = 0),
                          title: Text("bloc", style: TextStyle(fontSize: Global.WHS ? 15.sp : 11.sp, color: Colors.black)),
                        ),
                        ListTile(
                          onTap: () => setState(() => _currentIndex = 1),
                          title: Text("provider", style: TextStyle(fontSize: Global.WHS ? 15.sp : 11.sp, color: Colors.black)),
                        ),
                        ListTile(
                          onTap: () => setState(() => _currentIndex = 2),
                          title: Text("riverpod", style: TextStyle(fontSize: Global.WHS ? 15.sp : 11.sp, color: Colors.black)),
                        )
                      ],
                    ),
                  )
                ],
              )),
          Container(width: 3.w),
          Expanded(
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10)),
              ),
              child: Padding(padding: EdgeInsets.all(5), child: list[_currentIndex]),
            ),
          ),
        ],
      ),
    );
  }
}
